/*
 * Copyright (c) 2011-2012 Alexander Dubu
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * o  Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * o  Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * o  Neither the name Axil nor the names of its contributors may be used to
 *    endorse or promote products derived from this software without specific
 *    prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package axil.stdlib.money.type;

import java.util.Date;


/**
 * This interface is implemented by any class that can perform currency
 * conversion. This interface requires intimate knowledge of the Axil native
 * types of Money and Currency and is therefore not part of the language API.
 * It is recommended that custom currency converters be built in their own Jar
 * files so that only the converters have dependency on the Axil internals.
 */
public interface CurrencyConverter {
	/**
	 * Get the unique identity for this object. The string returned is never
	 * empty and contains no punctuation characters beyond a possible '-'. The
	 * value is suitable for use as an identifier.
	 */
	public String identity();


	/**
	 * Perform currency conversion on a given value. For example, to convert
	 * a $250.00 in US dollars as of 1962 to Japanese Yen as of today, the
	 * following is performed:
	 * <pre>
	 * 		Currency usd = Currency.from("USD");
	 * 		Currency jpy = Currency.from("JPY");
	 * 		Money amount = new Money(Decimal.from("250.00"), USD);
	 * 		convert(amount, jpy, new Date(1, 1, 1962), Date.today());
	 * </pre>
	 *
	 * @param from
	 * 	The amount to be converted. The amount given is never null.
	 *
	 * @param to
	 * 	The currency that the amount is to be converted to. The currency given
	 * 	is never null. The currency given may be the same as the currency of
	 * 	the amount, in which case the amount is adjusted for time.
	 *
	 * @param then
	 * 	The date when the given amount existed in that currency. The date given
	 * 	is never null.
	 *
	 *@param now
	 * 	The date when the currency conversion is logically performed. The date
	 * 	given is never null. The value returned is as of this date.
	 *
	 * @return
	 * 	Returns the amount converted to the target currency. A null value is
	 * 	returned if the conversion cannot be performed.
	 */
	public Money convert(Money from, Currency to, Date then, Date now);
}
